package inventory.common;

import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * 角色等级的枚举类，涉及的表 role 、repository
 */
public enum RoleLevelEnum implements Serializable {
    CITY("2","市"),
    COUNTY("1","县/区"),
    PERSON("0","个人");
    private String code;
    private String msg;

    RoleLevelEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }


    public String getMsg() {
        return msg;
    }

    /**
     * 通过code取枚举
     * @param code
     * @return
     */
    public static RoleLevelEnum getRoleLevelByCode(String code){
        if (StringUtils.isEmpty(code)){
            return null;
        }
        for (RoleLevelEnum enums : RoleLevelEnum.values()) {
            if (enums.getCode().equals(code)) {
                return enums;
            }
        }
        return null;
    }

    /**
     * 通过code取描述
     * @param code
     * @return
     */
    public static String getMagByCode(String code) {
        for (RoleLevelEnum enums : RoleLevelEnum.values()) {
            if (enums.getCode() == code) {
                return enums.getMsg();
            }
        }
        return "";
    }

}
